/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package olympicgamesgui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import olympicgameslogic.*;

/**
 *
 * @author Nuno
 */
public class DialogManageDisciplineEvents extends JDialog {

   private JTable eventsTable;
   private JScrollPane scroller;
   private DefaultTableModel TableModel;
   private LinkedList<DisciplineEvent> disciplineEvents;
   private ImageIcon img;
   private String tit;
   private int selectedLine;
   String[] columnNames = {"Event Name",  "Gender", "Round"};
   ClassLoader cldr = this.getClass().getClassLoader();

   public DialogManageDisciplineEvents(Frame father, String title, Discipline disc, DialogManageModalities dm) {
      super(father, title, true);
      super.setIconImage(Toolkit.getDefaultToolkit().getImage(cldr.getResource("images/extra/icon.png")));
      disciplineEvents = disc.getEventsList();
      setLayout(new BorderLayout());
      setBackground(Color.white);



      JPanel panNorth = new JPanel(new FlowLayout(FlowLayout.CENTER));
      panNorth.setSize(200, 60);
      panNorth.setBackground(Color.white);
      JLabel background = new JLabel(title);
      background.setFont(new Font("Arial", Font.BOLD, 14));
      background.setIcon(img);
      panNorth.add(background);


      JPanel panCenter = new JPanel();
      panCenter.setLayout(new BorderLayout(10, 10));
      panCenter.setBackground(Color.white);










      JPanel panCentertop = new JPanel(new FlowLayout(FlowLayout.CENTER));
      panCentertop.setBackground(Color.WHITE);

      JButton newButton = new JButton("New", new ImageIcon(cldr.getResource("images/extra/page_add.png")));
      newButton.addActionListener(new ActionListener() {

	 @Override
	 public void actionPerformed(ActionEvent e) {
	 }
      });
      JButton deleteButton = new JButton("Delete", new ImageIcon(cldr.getResource("images/extra/page_delete.png")));
      deleteButton.addActionListener(new ActionListener() {

	 @Override
	 public void actionPerformed(ActionEvent e) {
	 }
      });
  JButton editButton = new JButton("Edit", new ImageIcon(cldr.getResource("images/extra/page_edit.png")));
      deleteButton.addActionListener(new ActionListener() {

	 @Override
	 public void actionPerformed(ActionEvent e) {
	 }
      });
      panCentertop.add(newButton);
      panCentertop.add(deleteButton);
      panCentertop.add(editButton);

      panCenter.add(panCentertop,BorderLayout.NORTH);

      eventsTable = new JTable() {

	 public boolean isCellEditable(int rowIndex, int colIndex) {
	    return false; //Disallow the editing of any cell
	 }
      };
      TableModel = (DefaultTableModel) eventsTable.getModel();
      TableModel.setColumnIdentifiers(columnNames);
      setUpTableData();

      JTableHeader header = eventsTable.getTableHeader();
      header.setBackground(Color.DARK_GRAY);
      header.setFont(new Font("Arial", Font.BOLD, 12));
      header.setForeground(Color.WHITE);
      eventsTable.setPreferredScrollableViewportSize(new Dimension(300, 70));
      eventsTable.setFillsViewportHeight(true);
      eventsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      eventsTable.getSelectionModel().addListSelectionListener(new DialogManageDisciplineEvents.RowListener());
      eventsTable.getTableHeader().setReorderingAllowed(false);
      scroller = new JScrollPane(eventsTable);
      panCenter.add(scroller, BorderLayout.CENTER);


//painel com botoes        
      JPanel pansul = new JPanel();
      pansul.setSize(200, 20);
      pansul.setBackground(Color.white);
      JButton btCancel = new JButton("Exit", new ImageIcon(cldr.getResource("images/extra/btcancel.png")));
      pansul.setLayout(new FlowLayout(FlowLayout.CENTER));
      pansul.add(btCancel);


      add(panNorth, BorderLayout.NORTH);
      add(panCenter, BorderLayout.CENTER);
      add(pansul, BorderLayout.SOUTH);
      pack();
      setLocationRelativeTo(null);

      setDefaultCloseOperation(DISPOSE_ON_CLOSE);



      btCancel.addActionListener(new ActionListener() {

	 @Override
	 public void actionPerformed(ActionEvent e) {
	    dispose();
	 }
      });






   }

   public void showJan() {
      setVisible(true);





   }

   private class RowListener implements ListSelectionListener {

      @Override
      public void valueChanged(ListSelectionEvent event) {
//	 if (event.getValueIsAdjusting()) {
//	    return;
//	 }
//	 selectedLine = eventsTable.getSelectedRow();
//	 if (selectedLine == -1) {
//	    selectedLine = 0;
//	 } else {
//	    for (Discipline dis : mod.getDisciplines()) {
//	       if (eventsTable.getValueAt(selectedLine, 0).toString().equals(dis.getName())) {
//	//	  dis_temp = dis;
//	       }
//	    }
//	 }
      }
   }

   private void setUpTableData() {
      Object[][] data1 = new Object[disciplineEvents.getSize()][columnNames.length];
      int i = 0;

      for (DisciplineEvent ev : disciplineEvents) {
	 data1[i][0] = ev.getEventName();
	 data1[i][1] = ev.getEventGender();
	 data1[i][2] = ev.getRound();



	 TableModel.addRow(data1[i]);
	 i++;
      }
      eventsTable.setModel(TableModel);
   }

   public void refreshTable() {
      TableModel.setRowCount(0);
      eventsTable.removeAll();
      setUpTableData();
   }
}
